package info.xiao.dataStructrue.array;

import java.util.Arrays;

/**
 * @Classname MaximumProduct
 * @Description 三个数的最大乘积
 * @Url https://leetcode.cn/problems/maximum-product-of-three-numbers/
 * @Date 2023/4/13 10:17
 * @Created by 晓龙Oba
 */
public class MaximumProduct {
    public static void main(String[] args) {
        int[] nums = {-6, -1, 1, 3, 4};
        int result = maximumProduct(nums);
        System.out.println(result);
    }

    private static int maximumProduct(int[] nums) {
        Arrays.sort(nums);
        int a = nums[nums.length - 1] * nums[nums.length - 2] * nums[nums.length - 3];
        int b = nums[nums.length - 1] * nums[0] * nums[1];
        return a > b ? a : b;
    }
}
